package com.example.userserver.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.userserver.entity.CityInfo;
import com.example.userserver.entity.SchoolInfo;
import com.example.userserver.entity.UserInfo;
import com.example.userserver.mapper.SchoollnfoMapper;
import com.example.userserver.mapper.UserInfoMapper;
import com.example.userserver.params.PageSchoolInfoParams;
import com.example.userserver.params.PageUserInfoParams;
import com.example.userserver.utils.BeanCopyUtils;
import com.example.userserver.vo.SchoolInfoVO;
import com.example.userserver.vo.UserInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class SchoolInfoManager {
    @Autowired
    private SchoollnfoMapper schoollnfoMapper;

    public void insertSchoolInfo(SchoolInfo schoolInfo){
        schoollnfoMapper.insert(schoolInfo);
    }

    public void deleteSchoolInfo(String id){
        schoollnfoMapper.deleteById(id);
    }

    public void updateSchoolInfo(SchoolInfo schoolInfo){
        schoollnfoMapper.updateById(schoolInfo);
    }

    public List<SchoolInfoVO> listSchoolInfo(PageSchoolInfoParams pageSchoolInfoParams){
        QueryWrapper queryWrapper = new QueryWrapper();
        if( ! StringUtils.isEmpty(pageSchoolInfoParams.getSchoolName())){
            queryWrapper.like("school_name", pageSchoolInfoParams.getSchoolName());
        }
        if( ! StringUtils.isEmpty(pageSchoolInfoParams.getCityId())){
            queryWrapper.eq("city_id", pageSchoolInfoParams.getCityId());
        }
        return schoollnfoMapper.selectList(queryWrapper);
    }

    public SchoolInfoVO getSchoolInfo(String id){
        SchoolInfo schoolInfo = schoollnfoMapper.selectById(id);
        SchoolInfoVO schoolInfoVO = new SchoolInfoVO();
        BeanCopyUtils.copyPropertiesIgnoreNull(schoolInfo, schoolInfoVO);
        return schoolInfoVO;
    }
    public SchoolInfo selectSchool(QueryWrapper queryWrapper){
        SchoolInfo schoolInfo = schoollnfoMapper.selectOne(queryWrapper);
        return schoolInfo;
    }
}
